//
//  AOWelcomeController.swift
//  weibo_zha
//
//  Created by _zha on 16/10/25.
//  Copyright © 2016年 渣. All rights reserved.
//

import UIKit
import SDWebImage

class AOWelcomeController: UIViewController {
    
    override func loadView() {
        view = bgImageView
    }
    
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        //设置动画
        self.headImageView.snp_updateConstraints { (make) in
            make.top.equalTo(self.view).offset(100)
        }
        
        //设置阻尼动画
        UIView.animate(withDuration: 1, delay: 1, usingSpringWithDamping: 0.7, initialSpringVelocity: 0, options: [], animations: {
            self.view.layoutIfNeeded()
        }) { (_) in
            UIView.animate(withDuration: 0.25, animations: {
                self.messageLabel.alpha = 1
                }, completion: { (_) in
                    // 发通知切换根控制器04
                    NotificationCenter.default.post(name: NSNotification.Name(rawValue: AOSwitchRootVCNOTI), object: "welcomeVc")
            })
        }
    }

    
    override func viewDidLoad() {
        super.viewDidLoad()
    setupUI()
    }
    
    private func setupUI() {
        
        //添加控件
        view.addSubview(headImageView)
        view.addSubview(messageLabel)
        //添加约束
        headImageView.snp_makeConstraints { (make) in
            make.size.equalTo(CGSize(width: 90, height: 90))
            make.centerX.equalTo(view)
            make.top.equalTo(view).offset(400)
        }
        
        messageLabel.snp_makeConstraints { (make) in
            make.centerX.equalTo(view)
            make.top.equalTo(headImageView.snp_bottom).offset(16)
        }
    }
    
    
    //懒加载控件
    ///背景图片
    private lazy var bgImageView: UIImageView = UIImageView(imgName:"ad_background")
    ///头像
    private lazy var headImageView: UIImageView = {
        let img = UIImageView()
        img.layer.borderColor = AOHomeColor.cgColor
        img.layer.borderWidth = 1
        img.layer.cornerRadius = 45
        img.layer.masksToBounds = true
        img.ao_setImage(withUrlString: AOUserAccountViewModel.sharedTools.userAccountModel?.avatar_large, placeholderImgName: "avatar_default_big")
        return img
    }()
    ///文字
    private lazy var messageLabel: UILabel = {
        var lab = UILabel(textColor: AOHomeColor, fontSize: AOBigFontSize, text: "欢迎回来")
        
        lab.textAlignment = .center
        lab.alpha = 0
        
        return lab
    }()
}

   
    
